home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / include / liststring.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  1.8 KB  |  99 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1987, 1988, 1989 Stanford University
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8. #ifndef liststring_h
  9. #define liststring_h
  10.  
  11. #include "istring.h"
  12. #include "list2.h"
  13.  
  14. // A StringNode contains a pointer to a string of text.
  15.  
  16. class StringNode : public BaseNode 
  17. {
  18. public:
  19.     StringNode(const char*);
  20.     StringNode(const char*, int);
  21.     ~StringNode();
  22.     const char* GetString();
  23. protected:
  24.     char* string;        // points to a string of text
  25. };
  26.  
  27. // StringNode stores a duplicate of the given string of text.
  28.  
  29. static StringNode::StringNode (const char* text) 
  30. {
  31.     string = strdup(text);
  32. }
  33.  
  34. static StringNode::StringNode (const char* text, int length) 
  35. {
  36.     string = strndup(text, length);
  37. }
  38.  
  39. // Free storage allocated for the string.
  40.  
  41. static StringNode::~StringNode () 
  42. {
  43.     delete string;
  44. }
  45.  
  46. // Define inline access functions to get members' values.
  47.  
  48. inline const char* StringNode::GetString () 
  49. {
  50.     return string;
  51. }
  52.  
  53. // A StringList manages a list of StringNodes.
  54.  
  55. class StringList : public BaseList 
  56. {
  57. public:
  58.     StringNode* First();
  59.     StringNode* Last();
  60.     StringNode* Prev();
  61.     StringNode* Next();
  62.     StringNode* GetCur();
  63.     StringNode* Index(int);
  64. };
  65.  
  66. // Cast these functions to return StringNodes instead of BaseNodes.
  67.  
  68. inline StringNode* StringList::First () 
  69. {
  70.     return (StringNode*) BaseList::First();
  71. }
  72.  
  73. inline StringNode* StringList::Last () 
  74. {
  75.     return (StringNode*) BaseList::Last();
  76. }
  77.  
  78. inline StringNode* StringList::Prev () 
  79. {
  80.     return (StringNode*) BaseList::Prev();
  81. }
  82.  
  83. inline StringNode* StringList::Next () 
  84. {
  85.     return (StringNode*) BaseList::Next();
  86. }
  87.  
  88. inline StringNode* StringList::GetCur () 
  89. {
  90.     return (StringNode*) BaseList::GetCur();
  91. }
  92.  
  93. inline StringNode* StringList::Index (int index) 
  94. {
  95.     return (StringNode*) BaseList::Index(index);
  96. }
  97.  
  98. #endif
  99.